package cn.vc.content.controller.article;

import cn.vc.auth.entity.po.VUser;
import cn.vc.basicmodule.entity.Result;
import cn.vc.content.service.article.ArticleLikeService;
import cn.vc.content.service.article.ArticleService;
import cn.vc.content.util.SecurityUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/articlelike")
//@PreAuthorize("hasAnyAuthority('ordinary')")
public class ArticleLikeController {
    @Autowired
    private ArticleLikeService articleLikeService;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private ArticleService articleService;


    /**
     * <h2>点赞视频</h2>
     * @param id
     * @return
     */
    @PostMapping("/{id}")
    public Result<?> likeOrNot(@PathVariable("id") Long id) {
        VUser vUser = SecurityUtil.getUser();
        if (vUser==null) return Result.NOT_LOGGED_IN();
        boolean bo = articleLikeService.like(id, vUser.getId());
        if (bo) {
            articleService.like(id);
        } else {
            articleService.noLike(id);
        }
        return new Result<>(bo);
    }

}
